package com.kaizzi.data.ppt.template;

import com.fasterxml.jackson.databind.JsonNode;
import com.kaizzi.data.common.utils.DateUtil;
import com.kaizzi.data.common.utils.StringUtil;
import com.kaizzi.data.jdl.service.LogService;
import com.kaizzi.data.ppt.TemplateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
import org.apache.poi.xslf.usermodel.XSLFTextRun;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Kzen
 * @Description description
 * @date 2020/9/27
 */
@Component
@Slf4j
public class Template4 {

//    @Resource
//    private TemplateUtil templateUtil;
    @Resource
    private LogService logService;

    //text替换
    public void text(List<XSLFTextParagraph> textParagraphs, JsonNode data) {
        if(textParagraphs==null||textParagraphs.size()<1){
            return;
        }
        for (XSLFTextParagraph textParagraph : textParagraphs) {
            if(textParagraph==null){
                continue;
            }
            List<XSLFTextRun> textRuns = textParagraph.getTextRuns();
            if(textRuns==null || textRuns.size()<1 ){
                continue;
            }
            for (XSLFTextRun textRun : textRuns) {
                if (textRun == null || textRun.getRawText()  == null){
                    return;
                }
                try {
                    if (textRun.getRawText().equals("DATE")){
                        //段落样式
                        textRun.setText(DateUtil.getLastWeekDate());
                        break;
                    }
                }catch (Exception e){
                    logService.setDataLogStatus("ppt-error");
                    log.error("页码:{},异常原因:{}",4,e);
                }
            }
        }
    }

//    //数据
//    private JsonNode getJsonData(JsonNode data,String textName){
//        switch (textName){
//            case "4-KEY5":
//                return data.get("insights");
//            case "4-KEY4":
//                return data.get("actionPlan");
//            case "4-KEY1":
//                return data.get("summary");
//            default:
//                return data;
//        }
//    }
}
